package frog.whacker;

//import java.util.Random;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Frogs {
   
	//Members Variables
	private float mX;
    private float mY;
    private int mScore = 10;
    private Bitmap mBitmap;
    //private int mSpeedX;
    //private int mSpeedY;
     
    //Constructor
    public Frogs(double x, double y,Bitmap sBitmap) {
        //Random rand = new Random();
        mBitmap = sBitmap;
    	   boolean valid = false;
    	while (!valid)
    	{
	    	switch (this.checkBorders(x, y)){
		    	case 0:
		    		mX = (float) (x - mBitmap.getWidth() / 2);
			        mY = (float) (y - mBitmap.getHeight() / 2);
			        valid = true;
			        break;
		    	case 1:
		    		x = x + (mBitmap.getWidth() / 2);
		    		break;
		    	case 2:
		    		y = y + (mBitmap.getHeight() / 2);
		    		break;
		    	case 3:
		    		x = x - (mBitmap.getWidth() / 2);
		    		break;
		    	case 4:
		    		y = y - (mBitmap.getHeight() / 2);
		    		break;
	    	}
    	}
        //mSpeedX = rand.nextInt(7) - 3;
        //mSpeedY = rand.nextInt(7) - 3;
    }
    
    //Member Functions
    public int getScore()
    {
    	return mScore;
    }
    
    public void doDraw(Canvas canvas)
    {
    	Paint drawPaint = new Paint();
    	drawPaint.setAlpha(200);
    	canvas.drawBitmap(mBitmap, mX, mY, drawPaint );
    }
    
    public boolean checklocation(int x, int y)
    {
    	float X = mX;
    	float Y = mY;
    	if (x > X){
    		if (x < X + mBitmap.getWidth() ){
    			if (y > Y){
    	    		if (y < Y + mBitmap.getHeight() ){
    	    			return true;
    	    		}
    	    		else{return false;}
    			}
    			else{return false;}
    		}
    		else{return false;}
    	}
    	else{return false;}
    }
   
    public void animate(long elapsedTime) {
    	    	
    }

    private int checkBorders(double x, double y)
    {
        if (x - mBitmap.getWidth()/2  <= 0) {
            return 1;
        }
        else if (x + mBitmap.getWidth() >= Panel.mWidth) 
        {
            return 3;
        }
        if (y - mBitmap.getHeight()/2  <= 0) 
        {
            return 2;
        }
        else if (y + mBitmap.getHeight() >= Panel.mHeight)
        {
            return 4;
        }
        else
        {
        	return 0;
        }
    }
    
}
